﻿/// <reference path="../../Scripts/commen_js/MJ_JSComment.js" />
/// <reference path="../../Scripts/commen_js/jquery.cookie.min.js" />
/// <reference path="../../Scripts/commen_js/jquery-2.0.2.min.js" />
var ShowpinghCarObject = {
    BindBata: function () {
        var openid = $.cookie("openid");
        if (isUndefinedNullOrEmpty(openid)) {
            alert("下单失败请稍候再购买");
            return false;
        }
        poststr = "{\"type\":\"showpinghcar\",\"htmldata\":\"" + openid + "\"}";
        this.postajaxs(poststr, this.showdata);
    },
    showdata: function (data) {
        if (data.result == "ok") {
            var tabledata = data.table;
            var tableid = document.getElementById("tableid");
            $("#tableid").empty();
            try{
                if (tabledata.length != 0) {
                    for (var i = 0; i < tabledata.length; i++) 
                    {
                        var div0 = document.createElement("div");
                        div0.className = "media radiopading";
                        var div05 = document.createElement("div");
                        div05.className = "col-xs-1 padingset radionew";

                        var radio = document.createElement("input");
                        radio.setAttribute("type", "checkbox");
                        radio.className = "radio-inline text-center";
                        radio.value = "radio" + tabledata[i].id;
                        radio.setAttribute("name", "productradio");
                        div05.appendChild(radio);
                        div0.appendChild(div05);
                        var div1 = document.createElement("div");
                        div1.className = "col-xs-10";
                        var div2 = document.createElement("div");
                        div2.className = "media-left media-middle";
                        var img = document.createElement("img");
                        img.src = "../" + tabledata[i].childimg;
                        img.className = "media-object img";
                        div2.appendChild(img);
                        div1.appendChild(div2);

                        var div3 = document.createElement("div");
                        div3.className = "media-body";
                        var div4 = document.createElement("div");
                        div4.className = "media-heading";
                        div4.innerHTML = "产品名称：" + $.trim(tabledata[i].product_name) + $.trim(tabledata[i].product_type);
                        div3.appendChild(div4);
                        var div5 = document.createElement("div");
                        div5.className = "media-heading";
                        div5.innerHTML = "价格：" + $.trim(tabledata[i].price);
                        div3.appendChild(div4);
                        div3.appendChild(div5);
                        div1.appendChild(div3);
                        div0.appendChild(div1);
                        tableid.appendChild(div0);
                    }
                }
                }
                catch(e){}
            }
        else {
            layer_alert_error(data.msg);
        }
    },
    deleteproduct: function () {
        var str = document.getElementsByName("productradio");
        var objarray = str.length;
        var chestr = "";
        for (i = 0; i < objarray; i++) {
            if (str[i].checked == true) {
                chestr += "|" + str[i].value.replace("radio", "");
            }
        }
        if (chestr == "") {
            alert("请选择商品！");
            return;
        }
        //询问框
        layer.confirm('该商品确定删除？', {
            btn: ['确定', '取消'] //按钮
        }, function (index) {
            ShowpinghCarObject.senddelete();
            layer.close(index);
        }, function (index) {
            layer.close(index);
        });

    },

    senddelete: function () {
        var openid = $.cookie("openid");
        if (isUndefinedNullOrEmpty(openid)) {
            alert("操作请稍候再试");
            return false;
        }
        var str = document.getElementsByName("productradio");
        var objarray = str.length;
        var chestr = "";
        for (i = 0; i < objarray; i++) {
            if (str[i].checked == true) {
                chestr += "|" + str[i].value.replace("radio", "");
            }
        }
        if (chestr == "") {
            alert("请选择商品！");
            return;
        }
        var data = openid + chestr;
        poststr = "{\"type\":\"deleteshoppingcar\",\"htmldata\":\"" + data + "\"}";
        this.postajaxs(poststr, this.showdata);

    },


    get_radio_value: function () {
        var radio = $('input[name="payway"]').filter(':checked');
        if (radio.length) {
            return radio.val();
        }
        else {
            return "no_chosie";
        }
    },
    deleteproductrsult: function (data) {
        alert(data.msg);

    },
    buyproduct: function () {
        var str = document.getElementsByName("productradio");
        var objarray = str.length;
        var chestr = "";
        for (i = 0; i < objarray; i++) {
            if (str[i].checked == true) {
                if (chestr == "") {
                    chestr += str[i].value.replace("radio", "");
                }
                else {
                    chestr += "|" + str[i].value.replace("radio", "");
                }
            }
        }
        if (chestr == "") {
            alert("请选择相应的产品！");
            return;
        }
        location.href = "buy.aspx?" + "productid=" + chestr + "&resoretype=ShoppingCar&r=" + Math.random();
    },
    postajaxs: function (postdata, fangfa) {
        mj_ajax("../Handler1.ashx", "json", postdata, fangfa)
    }
}